import request from "@/utils/request";
import type {
  GetAttrInfoListParams,
  AttrInfoList,
  AttrInfoItem,
} from "./model/attrModel";

enum api {
  getAttrInfoList = "/admin/product/attrInfoList",
  addOrUpdateAttr = "/admin/product/saveAttrInfo",
  deleteAttr = "/admin/product/deleteAttr",
}

/**
 * 发送属性值列表请求
 * @param GetAttrInfoListParams
 * @returns AttrInfoList
 */
export const getAttrInfoList = ({
  category1Id,
  category2Id,
  category3Id,
}: GetAttrInfoListParams) => {
  return request.get<any, AttrInfoList>(
    api.getAttrInfoList + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 添加或者修改商品基础属性的请求
 * @param data
 * @returns null
 */
export const addOrUpdateAttrApi = (data: AttrInfoItem) => {
  return request.post<any, null>(api.addOrUpdateAttr, data);
};

/**
 * 删除属性
 * @param id ID
 * @returns null
 */
export const deleteAttrApi = (id: number) => {
  return request.delete<any, null>(api.deleteAttr + `/${id}`);
};
